package hc.j2me.ui;

import hc.core.data.DataInputEvent;
import hc.core.util.HCURL;
import hc.core.util.HCURLUtil;
import hc.j2me.util.ImageUtility;

import java.io.IOException;

import javax.microedition.lcdui.Image;
import javax.microedition.lcdui.game.Layer;
import javax.microedition.lcdui.game.LayerManager;
import javax.microedition.lcdui.game.Sprite;

public class HCPressShortPanel extends PressShortPanel {
	
	public HCPressShortPanel(HCCtrlGameCanvas canvas, LayerManager lm, Layer overLayer, final int _blockWidth, final int userMouseSplitWidth, final int _16){
		super(_blockWidth, canvas, 5);
		
		final String[] imgURL = {
				"/hc/j2me/res/ctrl_" + _16 + ".png",
				"/hc/j2me/res/sft_" + _16 + ".png",
				"/hc/j2me/res/m_mv_" + _16 + ".png",
				"/hc/j2me/res/mouse_rt_clk_" + _16 + ".png", 
				"/hc/j2me/res/cancel_" + _16 + ".png"};

		buildShortSprite(lm, overLayer, _blockWidth, userMouseSplitWidth, _16,
				imgURL);
	}

	public int actionIconIdx(int idx){
		if(idx == 0){
			ClickAt(HCURL.DATA_PARA_VALUE_CTRL);
			return HCCtrlGameCanvas.R_OK;
		}else if(idx == 1){
			ClickAt(HCURL.DATA_PARA_VALUE_SHIFT);
			return HCCtrlGameCanvas.R_OK;
		}else if(idx == 2){
			//点击move
			((HCCtrlGameCanvas)canvas).sp_mouseMove_cursor.setPosition(pressX, pressY);
			((HCCtrlGameCanvas)canvas).sendOutMouse(DataInputEvent.TYPE_MOUSE_MOVE);
			return HCCtrlGameCanvas.R_OK;
		}else if(idx == 3){
			//点击右键
			((HCCtrlGameCanvas)canvas).sp_mouseMove_cursor.setPosition(pressX, pressY);
			((HCCtrlGameCanvas)canvas).sendOutMouse(DataInputEvent.TYPE_MOUSE_RIGHT_CLICK);
			return HCCtrlGameCanvas.R_OK;
		}else if(idx == 4){
			//取消
			return HCCtrlGameCanvas.R_OK;
		}
		//自动忽略，取消
		return HCCtrlGameCanvas.R_CONTINUE;
	}

	private void ClickAt(String mode) {
		int targetX = canvas.locX + pressX;
		int targetY = canvas.locY + pressY;
		
		String[] para = {HCURL.DATA_PARA_RIGHT_CLICK, "x", "y"};
		String[] value = {mode, String.valueOf(targetX), String.valueOf(targetY)};
		HCURLUtil.sendCmd(HCURL.DATA_CMD_SendPara, para, value);
	}
}
